<?php
require_once("conf/db_connection.php");
$user_type = $_SESSION['type_nn'];
$stat = $_GET["stat"];
$return_str = "<div style='width:100%;background-color:#5F0C0C;text-align:center;color:#FFFFFF'>".strtoupper($stat)."</div>";

if($user_type=="agent")
{
	$query_tas = "SELECT id,truck_id,tas_number FROM trip_detail WHERE status='".$stat."' AND is_cancelled='0'";	
}
else if($user_type=="trucker")
{
	$query_tas = "SELECT id,truck_id,tas_number FROM trip_detail WHERE trucker_id='".$_SESSION["trucker_id_nn"]."' AND status='".$stat."' AND is_cancelled='0'";
}

$result_tas = mysql_query($query_tas) or die("SELECT TAS FAILED ".mysql_error());
while($row_tas = mysql_fetch_array($result_tas))
{
	$query_plate = "SELECT plate,contact_cellphone FROM truck WHERE id='".$row_tas["truck_id"]."'";
	$result_plate = mysql_query($query_plate) or die("SELECT PLATE ".mysql_error());
	$row_plate = mysql_fetch_array($result_plate);
	
	$tas_id = $row_tas['id'];
	$cell = substr(trim($row_plate['contact_cellphone']),-10);
	$truck_id = $row_tas["truck_id"];
	if($user_type=="agent")
	{
		$img_incident = "&nbsp;<img onClick=popStatusLog($cell,$truck_id); style='width:25px;height:25px;' src='image/status_log.png' title='Message List' />
		&nbsp;<img onClick=popIncident($tas_id); style='width:25px;height:25px;' src='image/incident.png' title='Incident List' />";
	}
	else if($user_type=="trucker")
	{
		$img_incident = "";
	}
	
	$query_stat_log = "SELECT * FROM status_log WHERE trip_detail_id='".$tas_id."' ORDER BY ID DESC";
	$result_stat_log = mysql_query($query_stat_log) or die("SELECT LOG ".mysql_error());
	$row_stat_log = mysql_fetch_array($result_stat_log);
	
	$inside_table = "<table border='0' style='margin-left:auto;margin-right:auto;font-weight:bold;'><tr><td onClick=popDetails($tas_id); title='View Details'>".$row_tas["tas_number"]." - ".$row_plate["plate"]."</td><td>".$img_incident."</td></tr></table>";
	$return_str .= "<div onMouseOver=this.style.backgroundColor='#BCC5C6'; onMouseOut=this.style.backgroundColor='#FFFFFF'; style='cursor:pointer;padding-top:5px;width:100%;text-align:center;'>".$inside_table."<span>".strtoupper($row_stat_log['updated_by'])." - ".$row_stat_log['update_date']."</span></div><hr />";
}
echo $return_str;
?>